package com.czy.owner.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;

import com.czy.owner.R;

import java.util.List;

/**
 * Created by King on 2016/6/16 0016.
 */
public class CarColorAdapter extends BaseRecyclerAdapter<String,CarColorAdapter.CarColorViewHolder> {
    private String selectedColor ;
    public CarColorAdapter(Context context, List<String> data, String selectedColor) {
        super(context, data);
        this.data = data;
        this.selectedColor = selectedColor;
    }

    @Override
    public void onBindViewHolder(CarColorViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.bindData(data.get(position));
    }

    @Override
    public CarColorViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new CarColorViewHolder(layoutInflater.inflate(R.layout.item_car_color_recycler, parent, false));
    }

    public class CarColorViewHolder extends BaseRecyclerAdapter.ViewHolder{
        private RadioButton rbColor;
        public CarColorViewHolder(View itemView) {
            super(itemView);
            rbColor = (RadioButton)itemView.findViewById(R.id.rb_item_car_color);
        }
        public void bindData(final String mColor){
            rbColor.setChecked(mColor.equals(selectedColor));
            rbColor.setTag(mColor);
            rbColor.setText(mColor);
            rbColor.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(selectedColor != mColor ) {
                        selectedColor = mColor;
                        notifyDataSetChanged();
                    }
                }
            });
        }
    }

    public String getSelectedColor() {
        return selectedColor;
    }
}
